package com.zhongxia.controller;

import com.zhongxia.entity.User;
import com.zhongxia.entity.UserVO;
import com.zhongxia.feign.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 废柴弟弟
 * @Date: 2020/4/1 11:51
 */
@Controller
@RequestMapping("clientuser")
public class ClientUser {
    @Autowired
    private UserFeign userFeign;
    @GetMapping("findAll")
    @ResponseBody
    public UserVO findAll(@RequestParam("page") int page, @RequestParam("limit") int limit)
    {
        int index=(page-1)*limit;
        return userFeign.findAll(index, limit);
    }

    @PostMapping("/save")
    //这里不用加requestbody，当调用另一个服务时，那个服务需要加
    public String save( User user){

        userFeign.save(user);
        return "redirect:/clientuser/index";
    }
    @GetMapping("index")
    public String index()
    {
        return "user_manage";
    }
    @GetMapping("add")
    public String add()
    {
        return "user_add";
    }
    @DeleteMapping("/deleteById/{id}")
    public String deleteById(@PathVariable("id") int id){
        userFeign.deleteById(id);
        return "redirect:/clientuser/index";
    }
    @GetMapping("count")
    public int count()
    {
        return userFeign.count();
    }
}
